package com.hospital.workstation.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.MedicationAdvisoryVo;
import com.hospital.workstation.domain.bo.MedicationAdvisoryBo;
import com.hospital.workstation.service.IMedicationAdvisoryService;
import com.hospital.common.core.page.TableDataInfo;

/**
 * 用药咨询
 *
 * @author whb
 * @date 2023-02-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/medicationAdvisory")
public class MedicationAdvisoryController extends BaseController {

    private final IMedicationAdvisoryService iMedicationAdvisoryService;

    /**
     * 查询用药咨询列表
     */
    @SaCheckPermission("workstation:medicationAdvisory:list")
    @GetMapping("/list")
    public TableDataInfo<MedicationAdvisoryVo> list(MedicationAdvisoryBo bo, PageQuery pageQuery) {
        return iMedicationAdvisoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取用药咨询详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("workstation:medicationAdvisory:query")
    @GetMapping("/{id}")
    public R<MedicationAdvisoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMedicationAdvisoryService.queryById(id));
    }

    /**
     * 新增用药咨询
     */
    @SaCheckPermission("workstation:medicationAdvisory:add")
    @Log(title = "用药咨询", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MedicationAdvisoryBo bo) {
        return toAjax(iMedicationAdvisoryService.insertByBo(bo));
    }

    /**
     * 修改用药咨询
     */
    @SaCheckPermission("workstation:medicationAdvisory:edit")
    @Log(title = "用药咨询", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MedicationAdvisoryBo bo) {
        return toAjax(iMedicationAdvisoryService.updateByBo(bo));
    }

    /**
     * 删除用药咨询
     *
     * @param ids 主键串
     */
    @SaCheckPermission("workstation:medicationAdvisory:remove")
    @Log(title = "用药咨询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMedicationAdvisoryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
